package model

import (
	"errors"
	"gitee.com/carollia/data-sdk-go/utils"
)

// 用户行为事件
type Entity struct {
	Type       string                 `json:"type"`
	Time       int64                  `json:"time"`
	Entity     string                 `json:"entity"`
	EntityId   string                 `json:"entity_id"`
	Properties map[string]interface{} `json:"properties"`
}

func (entity *Entity) Normalize() error {
	entity.Type = "entity"
	entity.Time = utils.GetCNTimeNow()
	// check uid
	if entity.EntityId == "" || len(entity.EntityId) == 0 {
		return errors.New("property [EntityId] can't be empty")
	}
	if len(entity.EntityId) > 255 {
		return errors.New("the max length of property [uid] is 255")
	}
	// check model
	if entity.Entity == "" {
		return errors.New("entity name can't be empty")
	}
	if entity.Properties == nil {
		entity.Properties = map[string]interface{}{}
	}
	return nil
}
